package com.wc.算法提高课.E第五章_数学知识.组合计数.数三角形;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/7 14:02
 * @description https://www.acwing.com/problem/content/1312/
 */
public class Main {
    /**
     * 思路：<p>
     * 总共有选法有 C(n * m, 3)<p>
     * 在同一条直线:<p>
     * 斜率为 0: n * C(m, 3) <p>
     * 斜率为 ∞ : m * C(n, 3) <p>
     * 斜率 > 0: /sum_1<=i<=n_1<=j<=m (gcd(i, j) - 1) * (n - i) * (m - j),  i, j表示线段的两条直角边, g(i, j) - 1, 表示线段之间的整数点个数, ((n - i), (m - j)) 表示可以选择的左下角点<p>
     * 斜边 < 0: 同上 <p>
     * res = C(n * m, 3) - n * C(n, 3) - m * C(m, 3) - /sum_1<=i<=n_1<=j<=m (gcd(i, j) - 1) * (n - i) * (m - j)
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010;
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt() + 1;
        m = sc.nextInt() + 1;
        long res = C(n * m) - n * C(m) - m * C(n);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                res -= 2L * (gcd(i, j) - 1) * (n - i) * (m - j);
            }
        }
        out.println(res);
        out.flush();
    }

    static int gcd(int a, int b) {
        return b > 0 ? gcd(b, a % b) : a;
    }

    static long C(int n) {
        return (long) n * (n - 1) * (n - 2) / 6;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
